#!/usr/bin/env python
# -*- coding: latin-1 -*-
import logging
from google.appengine.ext import webapp
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from google.appengine.ext.webapp.util import run_wsgi_app
class MailHandler(InboundMailHandler):
  def receive(self, message):
    bodies = message.bodies(content_type='text/plain')
    allBodies = "";
    for body in bodies:
      # body[0] = "text/plain"
      # body[1] = EncodedPayload --> body[1].decode()
      allBodies = allBodies + "\n---------------------------\n" + body[1].decode()
    #xmpp.send_message("email@gmail.com", "\n" + message.subject + allBodies)
    '''
    * subject contains the message subject.
    * sender is the sender's email address.
    * to is a list of the message's primary recipients.
    * cc contains a list of the cc recipients.
    * date returns the message date.
    * bodies is a list of message bodies, possibly including both plain text and HTML types. You can use the bodies() method to extract each body (see below).
    * attachments is a list of element pairs containing file types and contents.
    '''
    pass
application = webapp.WSGIApplication([
  MailHandler.mapping()
], debug=True)
def main():
  run_wsgi_app(application)
if __name__ == "__main__":
  main()